package com.lxd.sunso.product.controller;

import java.util.*;

import com.lxd.sunso.common.utils.PageUtils;
import com.lxd.sunso.common.utils.R;
import com.lxd.sunso.product.entity.DatatemplateEntity;
import com.lxd.sunso.product.entity.TemplateEntity;
import com.lxd.sunso.product.vo.MonitorDataVo;
import com.lxd.sunso.product.vo.RealDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lxd.sunso.product.entity.ControlrealtimeEntity;
import com.lxd.sunso.product.service.ControlrealtimeService;


/**
 * @author lxd
 * @email sunlightcs@gmail.com
 * @date 2020-12-30 18:06:30
 */
@RestController
@RequestMapping("product/controlrealtime")
public class ControlrealtimeController {
    @Autowired
    private ControlrealtimeService controlrealtimeService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:controlrealtime:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = controlrealtimeService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:controlrealtime:info")
    public R info(@PathVariable("id") Long id) {
        ControlrealtimeEntity controlrealtime = controlrealtimeService.getById(id);

        return R.ok().put("controlrealtime", controlrealtime);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:controlrealtime:save")
    public R save(@RequestBody ControlrealtimeEntity controlrealtime) {
        controlrealtimeService.save(controlrealtime);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:controlrealtime:update")
    public R update(@RequestBody ControlrealtimeEntity controlrealtime) {
        controlrealtimeService.updateById(controlrealtime);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:controlrealtime:delete")
    public R delete(@RequestBody Long[] ids) {
        controlrealtimeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 根据的相关条件获取设备的状态
     */
    @RequestMapping("/listByCondition")
    public R listByCustomer(@RequestParam Map<String, Object> params) {
        RealDataVo realDataVo = controlrealtimeService.listByCondition(params);
        return R.ok().put("page", realDataVo);
    }

    @RequestMapping("/listBytemplate/{id}")
    public R listBytemplate(@PathVariable("id") Integer id) {
        ArrayList<HashMap<String, String>> hashMaps = controlrealtimeService.listBytemplate((id));
        return R.ok().put("page", hashMaps);
    }

    /**
     * 根据客户的名称获取可用的数据模板
     */
    @RequestMapping("/searchTemplate/{customerName}")
    public R searchTemplate(@PathVariable String customerName) {
        List<TemplateEntity> list = controlrealtimeService.searchTemplate(customerName);
        return R.ok().put("page", list);
    }

    /**
     * 根据设备的名称获取完整的信息
     */
    @RequestMapping("/listByMachine/{machineName}")
    public R listByMachine(@PathVariable String machineName) {
        List<MonitorDataVo> list = controlrealtimeService.listByMachine(machineName);
        return R.ok().put("page", list);
    }

    /**
     * 根据设备型号获取到所有的数据模板
     */
    @RequestMapping("/searchTemplateByKind/{id}")
    public R searchTemplateByKind(@PathVariable Long id) {
        List<TemplateEntity> list = controlrealtimeService.searchTemplateByKind(id);
        return R.ok().put("page", list);
    }
}
